package com.demos.springcloud.provider00Exception.controller;

import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("exp")
public class controller {

    @PostMapping("post/{id}")
    public Map<String, Object> service1(@PathVariable(name="id") String id){
        System.out.println(LocalDateTime.now() + " exp01 : " + id);

        if(System.currentTimeMillis() % 2 == 0) {
            throw new RuntimeException("报错01");
        }

        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", "exception");
        map.put("result", "success");
        map.put("Thread", Thread.currentThread().getName());
        return map;
    }

    @GetMapping("timeout")
    public String service2() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return Thread.currentThread().getName() + " wait 5s";
    }
}
